package leetcode_201_300;

import java.lang.annotation.Target;

public class LeeCode_240 {
    public static void main(String[] args) {
        System.out.println(searchMatrix(new int[][]{
                {1, 2, 3, 4, 5},
                {6, 7, 8, 9, 10},
                {11, 12, 13, 14, 15},
                {16, 17, 18, 19, 20},
                {21, 22, 23, 24, 25}}, 15));
    }

    private static boolean searchMatrix(int[][] matrix, int target) {
        return dfs(matrix, 0, matrix[0].length - 1, target);
    }
    private static boolean dfs(int[][] matrix, int i, int j, int target){
        if (i >= matrix.length || j < 0){
            return false;
        }
        int val = matrix[i][j];
        if (target == val) {
            return true;
        }
        if (target < val){
            return dfs(matrix, i, j - 1, target);
        }else {
            return dfs(matrix, i + 1, j, target);
        }
    }
}
